home *** CD-ROM | disk | FTP | other *** search
/ Aminet 5 / Aminet 5 - March 1995.iso / Aminet / misc / edu / globe099src.lha / Ami-Globe / map_divers.c < prev    next >
C/C++ Source or Header  |  1994-11-17  |  10KB  |  324 lines

  1. /************************************************************************/
  2. /*                                                                      */
  3. /*      fichier         : map_divers.c                                  */
  4. /*      projet          : amiglobe                                      */
  5. /*      date création   : juillet 94                                    */
  6. /*      commentaire     : Affichage des éléments remarquables           */
  7. /*      révision        : $VER: map_divers.c 2.002 (10 Sep 1994) */
  8. /*      copyright       : Olivier Collard, Thomas Landspurg             */
  9. /*     $HISTORY:                                                */
  10. /*                     juillet 1994 : 0.01 : version initiale           */
  11. /*                                                                      */
  12. /************************************************************************/
  13.  
  14.  
  15. /************************************************************************/
  16. /*      includes                                                        */
  17. /************************************************************************/
  18.  
  19. #include <clib/graphics_protos.h>
  20. #include <clib/intuition_protos.h>
  21. #include <stdio.h>
  22. #include <math.h>
  23. #include <stdlib.h>
  24. #include <utility/hooks.h>
  25. #include "amiglobe_types.h"
  26. #include "database_types.h"
  27. #include "map_function_protos.h"
  28. #include "database_protos.h"
  29. #include "map_divers.h"
  30.  
  31. /************************************************************************/
  32. /*      variables externes                                              */
  33. /************************************************************************/
  34.  
  35. extern int num_first_color;
  36. extern PREFERENCE Pref;
  37. extern COUNTRY * tab_country;
  38. extern struct Screen * sC;
  39. extern TRAJECTOIRE ** tab_trajectoire;
  40.  
  41. /************************************************************************/
  42. /*      defines                                                         */
  43. /************************************************************************/
  44.  
  45. #define COLOR_SELECT_PAYS   1
  46. #define COLOR_SELECT_SEG    2
  47. #define COLOR_BLEU      0
  48. #define COLOR_COTE      1
  49.  
  50. /************************************************************************/
  51. /*      prototypes fonctions privées                                    */
  52. /************************************************************************/
  53.  
  54. void Map_Aff_Capitale (struct RastPort * rpG,ELEM_REM * element);
  55. void Map_Aff_Ville    (struct RastPort * rpG,ELEM_REM * element);
  56. void Map_Aff_Montagne (struct RastPort * rpG,ELEM_REM * element);
  57. void Map_Aff_Monument (struct RastPort * rpG,ELEM_REM * element);
  58.  
  59.  
  60. /************************************************************************/
  61. /*      implémentation                                                  */
  62. /************************************************************************/
  63.  
  64. /* -------------------------- est_dedans(int x,int y) --------------------------
  65.  
  66.  Commentaire: renvoie TRUE si le point (x,y) est dans le clip_cur
  67.  
  68. */
  69.  
  70. BOOL
  71. est_dedans(int x,int y)
  72. {
  73.     if ((x>Pref.clip_cur.minx) && (x<Pref.clip_cur.maxx) && 
  74.         (y>Pref.clip_cur.miny) && (y<Pref.clip_cur.maxy))
  75.         return TRUE;
  76.     else
  77.         return FALSE;
  78. }
  79.  
  80.  
  81. void Map_Aff_Elem_Rem(struct RastPort * rpG,ELEM_REM * element)
  82. {
  83.     CLIP element_clip;      
  84.     SetAPen(rpG,COLOR_SELECT_SEG+num_first_color);
  85.     element_clip.minx=element_clip.maxx=element->Lon;
  86.     element_clip.miny=element_clip.maxy=element->Lat;
  87.     if (tstclip(Pref.clip_cur.minx,Pref.clip_cur.miny,
  88.             Pref.clip_cur.maxx,Pref.clip_cur.maxy,
  89.             &element_clip)==TRUE)
  90.     //if (est_dedans(element->Lon,element->Lat)==TRUE)
  91.     {
  92.         switch (element->Type)
  93.         {
  94.             case CAPITALE:
  95.                 Map_Aff_Capitale(rpG,element);
  96.                 break;
  97.             case VILLE:
  98.                 Map_Aff_Ville(rpG,element); 
  99.                 break;
  100.             case MONUMENT:
  101.                 Map_Aff_Monument(rpG,element);
  102.                 break;
  103.             case MONTAGNE:
  104.                 Map_Aff_Montagne(rpG,element);
  105.                 break;
  106.             default:
  107.                 break;
  108.         }
  109.     }
  110. }
  111.  
  112. /* -------- Map_Aff_Capitale (struct RastPort  rpG,ELEM_REM  element) --------
  113.  
  114.  Commentaire: dessine sur la carte une capitale
  115.  
  116. */
  117.  
  118. void
  119. Map_Aff_Capitale (struct RastPort  * rpG,ELEM_REM * element)
  120. {
  121.     int sx=Pref.clip_cur.maxx-Pref.clip_cur.minx;
  122.     if (element->caracteristique+300000>50*sx)
  123.     {
  124.         int delta=sqrt((double)element->caracteristique)/500+2;
  125.         int minx=element->Lon-delta;
  126.         int maxx=element->Lon+delta;
  127.         int miny=element->Lat-delta*sC->Height*640/sC->Width/512;
  128.         int maxy=element->Lat+delta*sC->Height*640/sC->Width/512;
  129.         conv_xy(&minx,&miny);
  130.         conv_xy(&maxx,&maxy);
  131.         SetAPen(rpG,6+num_first_color);
  132.         Move(rpG,minx,miny);
  133.         Draw(rpG,maxx,miny);
  134.         Draw(rpG,maxx,maxy);
  135.         Draw(rpG,minx,maxy);
  136.         Draw(rpG,minx,miny);
  137.         if (element->caracteristique+300000>175*sx)
  138.             IPrintFond(rpG,maxx,(maxy+miny)/2,element->Nom,
  139.                     -num_first_color);
  140.     }
  141. }
  142.  
  143. void Map_Aff_Ville (struct RastPort * rpG,ELEM_REM * element)
  144. {
  145.     int sx=Pref.clip_cur.maxx-Pref.clip_cur.minx;
  146.     if (element->caracteristique+200000>50*sx)
  147.     {
  148.         int delta=sqrt((double)element->caracteristique)/500+2;
  149.         int minx=element->Lon-delta;
  150.         int maxx=element->Lon+delta;
  151.         int y1=element->Lat;
  152.         int y2=element->Lat;
  153.         conv_xy(&minx,&y1);
  154.         conv_xy(&maxx,&y2);
  155.         delta=(maxx-minx)/2;
  156.         SetAPen(rpG,5+num_first_color);
  157.         DrawEllipse(rpG,(minx+maxx)/2,y1,delta,delta*sC->Height*640/sC->Width/512);
  158.         if (element->caracteristique+200000>175*sx)
  159.             IPrintFond(rpG,maxx,y2,element->Nom,-num_first_color);
  160.     }
  161. }
  162.  
  163. void Map_Aff_Montagne (struct RastPort * rpG,ELEM_REM * element)
  164. {
  165.     int sx=Pref.clip_cur.maxx-Pref.clip_cur.minx;
  166.     if (element->caracteristique>sx/2)
  167.     {
  168.         float delta=element->caracteristique/300;
  169.         int minx=element->Lon-delta/4;
  170.         int maxx=element->Lon+delta/4;
  171.         int miny=element->Lat-delta/2;
  172.         int maxy=element->Lat+delta/2;
  173.         conv_xy(&minx,&miny);
  174.         conv_xy(&maxx,&maxy);
  175.         SetAPen(rpG,2L);
  176.         Move (rpG,minx,maxy);
  177.         Draw (rpG,maxx,maxy);
  178.         Draw (rpG,(minx+maxx)/2,miny);
  179.         Draw (rpG,minx,maxy);
  180.         if (element->caracteristique>sx)
  181.             IPrintFond (rpG,maxx,maxy,element->Nom,-num_first_color);
  182.     }
  183. }
  184.  
  185. void Map_Aff_Monument (struct RastPort * rpG,ELEM_REM * element)
  186. {
  187.     int sx=Pref.clip_cur.maxx-Pref.clip_cur.minx;
  188.     if (element->caracteristique>sx/50)
  189.     {
  190.         int delta=element->caracteristique/20;
  191.         int x=element->Lon-delta;
  192.         int y=element->Lat;
  193.         int x1,y1,x2,y2;
  194.         conv_xy(&x,&y);
  195.         SetAPen(rpG,5+num_first_color);
  196.         Move (rpG,x,y);
  197.         x=element->Lon+delta;
  198.         y=element->Lat;
  199.         conv_xy(&x,&y);
  200.         Draw (rpG,x,y);
  201.         x1=element->Lon-delta/2;
  202.         y1=element->Lat-delta*0.83;
  203.         x2=element->Lon+delta/2;
  204.         y2=element->Lat+delta*0.83;
  205.         conv_xy(&x1,&y1);
  206.         conv_xy(&x2,&y2);
  207.         Move (rpG,x1,y1);
  208.         Draw (rpG,x2,y2);
  209.         Move (rpG,x1,y2);
  210.         Draw (rpG,x2,y1);
  211.         if (element->caracteristique>sx/25)
  212.             IPrintFond (rpG,x2,y,element->Nom,-num_first_color);
  213.     }           
  214. }
  215.  
  216. void map_aff_point(struct RastPort * rpG, POINT * point, int couleur)
  217. {
  218.     if (point->existe==TRUE)
  219.     {
  220.         int x=point->longitude;
  221.         int y=point->latitude;
  222.         if (tstclip(x,y,x,y,&Pref.clip_cur)==TRUE)
  223.         {
  224.             conv_xy(&x,&y);
  225.             SetAPen(rpG,COLOR_SELECT_SEG+num_first_color+couleur);
  226.             Move(rpG,x-12,y);
  227.             Draw(rpG,x-2,y);
  228.             Move(rpG,x+2,y);
  229.             Draw(rpG,x+12,y);
  230.             Move(rpG,x,y-12*sC->Height*640/(sC->Width*512));
  231.             Draw(rpG,x,y-2*sC->Height*640/(sC->Width*512));
  232.             Move(rpG,x,y+12*sC->Height*640/(sC->Width*512));
  233.             Draw(rpG,x,y+2*sC->Height*640/(sC->Width*512));
  234.         }
  235.     }
  236. }
  237. /*
  238. LONG __asm aff_nom_elem_rem (
  239.     register __a2 char **array, 
  240.     register __a1 ELEM_REM * element)
  241. {
  242.     static char buffer[20];
  243.     sprintf(buffer,"%s",element->Name);
  244.     *array=buffer;
  245.     return (0);
  246. }*/
  247.  
  248. /****************************************************************************/
  249.  
  250. void
  251. aff_donnees(struct RastPort *rpG,DATA_TRI * donnee,int valeur_max,E_Type_Data type,int nb_plage,int nb_data)
  252. {
  253.     /* on suppose les données triées */
  254.     int i;
  255.     int color=5;
  256.     int nb_pays=0;
  257.     for (i=0;i<nb_data;i++)
  258.     {
  259.         /* methode n°1: nombre égal de pays ayant la même couleur */
  260.         nb_pays++;
  261.         if (nb_pays>nb_data/6)
  262.         {
  263.             nb_pays=0;
  264.             color--;
  265.         }
  266.         /*  methode n°2: distribution égale de la valeur
  267.         switch (type)
  268.         {
  269.           case DATA_FLOAT:
  270.           case DATA_PERCENT:
  271.               color=donnee[i].valeur.data_float*6/valeur_max;
  272.               break;
  273.           case DATA_INTEGER:
  274.           default:
  275.               color=donnee[i].valeur.data_int*6/valeur_max;
  276.               break;
  277.         } */
  278.     /*      switch (type)
  279.             {
  280.             case POPULATION:
  281.                 color=log10((double)tab_country[i].population)-4;
  282.                 break;
  283.             case SUPERFICIE:
  284.                 color=log10((double)tab_country[i].superficie)-3;
  285.                 break;
  286.             case DENSITE:
  287.                 color=log10((double)tab_country[i].population/tab_country[i].superficie)*6/3;
  288.                 break;
  289.             case PNB:
  290.                 color=log10((double)tab_country[i].PIB)-2;
  291.                 break;
  292.             case PNB_HAB:
  293.                 color=(log10((double)tab_country[i].PIB/tab_country[i].population)-2)*6/4;
  294.                 break;
  295.             }*/
  296.             if (color<0)
  297.                 color=0;
  298.             if (color>5)
  299.                 color=5;        
  300.             fill_country(donnee[i].Num_Pays,color+6,rpG);
  301.             /*printf("couleur :%d\n",color);*/
  302.         
  303.     }
  304. }
  305.  
  306. /* ------------------------------ point_est_dans -------------------------------
  307.  
  308.  Commentaire:renvoie TRUE si le point de coordonnées (x,y) est dans le
  309.              clip clip.
  310.  
  311. */
  312.  
  313. BOOL
  314. point_est_dans(int x,int y,CLIP * clip)
  315. {
  316.     if (x>=clip->minx && x<=clip->maxx
  317.         && y>=clip->miny && y<=clip->maxy)
  318.         return TRUE;
  319.     else
  320.         return FALSE;
  321. }
  322.  
  323.  
  324.